package com.md.value;

import com.md.base.EnumBase;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author 刘骄阳
 * @date 23/5/25 15:21
 **/
@Getter
@AllArgsConstructor
public enum GlobalConfigTypeEnum implements EnumBase {
  /**
   * 默认角色
   */
  DEFAULT_ROLE(0, "默认角色"),
  /**
   * 默认头像
   */
  DEFAULT_AVATAR(1, "默认头像");

  static final Map<Integer, GlobalConfigTypeEnum> ENUM_MAP = Arrays.stream(GlobalConfigTypeEnum.values())
    .collect(Collectors.toMap(GlobalConfigTypeEnum::getCode, e -> e));

  static final Map<String, GlobalConfigTypeEnum> ENUM_MAP_STRING = Arrays.stream(GlobalConfigTypeEnum.values())
    .collect(Collectors.toMap(GlobalConfigTypeEnum::getMessage, e -> e));
  private final Integer code;
  private final String message;

  public static GlobalConfigTypeEnum of(final Integer code) {
    return ENUM_MAP.get(code);
  }

  /**
   * 根据值获取对应的枚举
   *
   * @param message code 值
   * @return 枚举对应的值
   */
  public static EnumBase of(final String message) {
    return ENUM_MAP_STRING.get(message);
  }


}
